#include "Utility.h"

//returns a string version of the integer parameter
std::string Utility::toString(int x){
    std::string s1;
    std::stringstream out;
    out << x;
    return out.str();
}

// returns a random int between min and max
int Utility::random(int min, int max) //range : [min, max)
{
   static bool first = true;
   if ( first )
   {
      srand(time(NULL)); //seeding for the first time only!
      first = false;
   }
   return min + rand() % (max - min);
}

//Returns the angle between two points
float Utility::computeDirection(sf::Vector2f p1, sf::Vector2f p2){
    return atan2 (p2.y - p1.y , p2.x - p1.x) * 180 / PI;
}

//Returns the distance between two points
double Utility::computeDistance(sf::Vector2f p1, sf::Vector2f p2){
    return sqrt((p2.x - p1.x)*(p2.x - p1.x) + (p2.y - p1.y)*(p2.y - p1.y));
}
